//
//  ZFBBusinessHeaderView.m
//  Gunterapple
//
//  Created by 热带雨林 on 2020/4/2.
//  Copyright © 2020 热带雨林. All rights reserved.
//

#import "ZFBBusinessHeaderView.h"
#import "GGZFBBusinessHeaserFlowLayout.h"
#import "ZFBBusinessTypeModel.h"
#import "GGAddtion.h"
#import "GGZFBBusinessHeaderCell.h"
static NSString *cellID = @"cellID";
@interface ZFBBusinessHeaderView ()<UICollectionViewDataSource, UICollectionViewDelegate>
@property (nonatomic, weak)UIImageView *imageview;
@property (nonatomic, weak) UICollectionView *collectionView;
@property (nonatomic, strong) NSMutableArray <ZFBBusinessTypeModel *>*dataList;
@end
@implementation ZFBBusinessHeaderView

- (instancetype)initWithFrame:(CGRect)frame{
    if(self = [super initWithFrame:frame]){
        [self loadData];
        [self setUpUI];
    }
    return self;
}
- (void)setUpUI{
    UIImageView *image = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.frame), 350)];
    self.imageview = image;
    self.imageview.image = [UIImage imageNamed:@"business_ad_001"];
    [self addSubview:image];
    
    GGZFBBusinessHeaserFlowLayout *layout = [[GGZFBBusinessHeaserFlowLayout alloc]init];
    UICollectionView *collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 350, CGRectGetWidth(self.frame), 300) collectionViewLayout:layout];
    collectionView.backgroundColor = [UIColor whiteColor];
    collectionView.delegate = self;
    collectionView.dataSource = self;
    collectionView.showsVerticalScrollIndicator = NO;
    [collectionView registerClass:[GGZFBBusinessHeaderCell class] forCellWithReuseIdentifier:cellID];
    [self addSubview:collectionView];
}
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    return 1;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return self.dataList.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    GGZFBBusinessHeaderCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellID forIndexPath:indexPath];
    cell.model = self.dataList[indexPath.item];
    return cell;
}
- (void)loadData{
    self.dataList = [NSArray gg_arrayModelWithPlistName:@"businessType.plist" withClassName:@"ZFBBusinessTypeModel"].mutableCopy;
}
- (NSMutableArray <ZFBBusinessTypeModel *>*)dataList{
    if(!_dataList){
        _dataList = [NSMutableArray array];
    }
    return _dataList;
}
@end
